package com.example.mall.web.controller;

import com.example.mall.domain.UserRetentionStatistics;
import com.example.mall.dto.UserRetentionStatisticsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.UserRetentionStatisticsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IUserRetentionStatisticsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userRetentionStatistics")
public class UserRetentionStatisticsController {

    @Autowired
    public IUserRetentionStatisticsService userRetentionStatisticsService;

    /**
     * 分页查询用户留存率分析表信息
     * @param userRetentionStatisticsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询用户留存率分析表信息",notes = "分页查询用户留存率分析表信息",httpMethod = "GET")
    public JSONResult queryPage(UserRetentionStatisticsQuery userRetentionStatisticsQuery){
        PageDTO<UserRetentionStatisticsDto> userRetentionStatisticsDtoPageDTO = userRetentionStatisticsService.queryPage(userRetentionStatisticsQuery);
        return JSONResult.success("查询成功",userRetentionStatisticsDtoPageDTO);
    }

    /**
     * 根据id查询用户留存率分析表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询用户留存率分析表信息",notes = "根据id查询用户留存率分析表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.USER_RETENTION_STATID_NOT_ID);
        }
        UserRetentionStatistics userRetentionStatistics = userRetentionStatisticsService.getById(id);
        return JSONResult.success("查询成功",userRetentionStatistics);
    }

    /**
     * 根据id查询用户留存率分析表信息
     * @param id
     * @return
     */
    @GetMapping("queryUserRetentionStatisticsById/{id}")
    @ApiOperation(value = "根据id查询用户留存率分析表信息",notes = "根据id查询用户留存率分析表信息",httpMethod = "GET")
    public JSONResult queryUserRetentionStatisticsById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.USER_RETENTION_STATID_NOT_ID);
        }
        UserRetentionStatistics userRetentionStatistics = userRetentionStatisticsService.queryUserRetentionStatisticsById(id);
        return JSONResult.success("查询成功",userRetentionStatistics);
    }

    /**
     * 查询全部用户留存率分析表信息
     * @param
     * @return
     */
    @GetMapping("queryUserRetentionStatisticsList")
    @ApiOperation(value = "查询全部用户留存率分析表信息",notes = "查询全部用户留存率分析表信息",httpMethod = "GET")
    public JSONResult queryUserRetentionStatisticsList(){
        List<UserRetentionStatistics> userRetentionStatistics = userRetentionStatisticsService.queryUserRetentionStatisticsList();
        return JSONResult.success("查询成功",userRetentionStatistics);
    }

    /**
     * 新增用户留存率分析表
     * @param userRetentionStatisticsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增用户留存率分析表",notes = "新增用户留存率分析表",httpMethod = "POST")
    public JSONResult insert(@RequestBody UserRetentionStatisticsDto userRetentionStatisticsDto){
        userRetentionStatisticsService.insert(userRetentionStatisticsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改用户留存率分析表信息
     * @param userRetentionStatisticsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改用户留存率分析表信息",notes = "修改用户留存率分析表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody UserRetentionStatisticsDto userRetentionStatisticsDto){
        userRetentionStatisticsService.update(userRetentionStatisticsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除用户留存率分析表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除用户留存率分析表信息",notes = "删除用户留存率分析表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        userRetentionStatisticsService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除用户留存率分析表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除用户留存率分析表信息",notes = "批量删除用户留存率分析表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        userRetentionStatisticsService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
